package com.zhiche.lisa.bms.controller.driver;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.pojo.vo.driver.BaseCvQueryConditionsVO;
import com.zhiche.lisa.bms.pojo.vo.driver.BaseCvTankvolumeVO;
import com.zhiche.lisa.bms.service.driver.IBaseCvTankvolumeService;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 商品车型油箱容积, cv = commercial vehicle 前端控制器
 * </p>
 *
 * @author zhaoguixin
 * @since 2018-08-30
 */
@RestController
@RequestMapping("/cv_TankVolume")
@Slf4j
@Api(description = "商品车型油箱容积", tags = {"商品车型油箱容积"})
public class BaseCvTankvolumeController {

    @Autowired
    private IBaseCvTankvolumeService baseCvTankvolumeService;

    @PostMapping(value = "/page_list")
    @ApiOperation(value = "分页获得商品车型油箱容积", notes = "分页获得商品车型油箱容积",
            produces = MediaType
                    .APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = BaseCvTankvolumeVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<BaseCvTankvolumeVO>> listByPage(@ApiParam(name = "BaseCvTankvolumeVO", value = "商品车型油箱容积", required = true) @RequestBody Page<BaseCvTankvolumeVO> pageVo) {
        log.info("BaseCvTankvolumeController.listByPage params : {}", pageVo);
        RestfulResponse<Page<BaseCvTankvolumeVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(baseCvTankvolumeService.listByPage(pageVo));
        } catch (BaseException e) {
            log.error("BaseCvTankvolumeController.listByPage ERROR:{}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            log.error("BaseCvTankvolumeController.listByPage ERROR:{} ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/list")
    @ApiOperation(value = "获得商品车型油箱容积列表", notes = "获得商品车型油箱容积列表",
            produces = MediaType
                    .APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = BaseCvTankvolumeVO.class), @ApiResponse(code = -1, message = "系统异常")})
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "String", name = "cvTypeId", value = "车型ID", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "tankVolume", value = "车型油箱容积", required = true)})
    public RestfulResponse<List<BaseCvTankvolumeVO>> list(BaseCvQueryConditionsVO conditions) {
        log.info("BaseCvTankvolumeController.list param : {}", conditions);
        RestfulResponse<List<BaseCvTankvolumeVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(baseCvTankvolumeService.selectListByConditions(conditions));
        } catch (BaseException e) {
            log.error("BaseCvTankvolumeController.list ERROR:{}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            log.error("BaseCvTankvolumeController.list ERROR:{} ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }


    @PostMapping(value = "/add")
    @ApiOperation(value = "添加", notes = "添加",
            produces = MediaType
                    .APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Integer.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Integer> add(@ApiParam(name = "BaseCvTankvolumeVO", value = "商品车型油箱容积VO", required = true) @RequestBody @Valid BaseCvTankvolumeVO baseCvTankvolumeVO, BindingResult br) {
        log.info("BaseCvTankvolumeController.add param : {}", baseCvTankvolumeVO);
        RestfulResponse<Integer> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(baseCvTankvolumeService.add(baseCvTankvolumeVO, br));
        } catch (BaseException e) {
            log.error("BaseCvTankvolumeController.add ERROR:{}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            log.error("BaseCvTankvolumeController.add ERROR:{} ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }


    @PostMapping(value = "/update")
    @ApiOperation(value = "更新", notes = "更新",
            produces = MediaType
                    .APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Boolean.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Boolean> update(@ApiParam(name = "BaseCvTankvolumeVO", value = "商品车型油箱容积VO", required = true) @RequestBody @Valid BaseCvTankvolumeVO baseCvTankvolumeVO, BindingResult br) {
        log.info("BaseCvTankvolumeController.update param : {}", baseCvTankvolumeVO);
        RestfulResponse<Boolean> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Boolean blnRtn = baseCvTankvolumeService.update(baseCvTankvolumeVO, br);
            result.setData(blnRtn);
        } catch (BaseException e) {
            log.error("BaseCvTankvolumeController.update ERROR:{}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            log.error("BaseCvTankvolumeController.update ERROR:{} ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }


    @GetMapping(value = "/getById")
    @ApiOperation(value = "根据ID查找商品车型油箱容积", notes = "根据ID查找商品车型油箱容积",
            produces = MediaType
                    .APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "id", value = "id", required = true)})
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = BaseCvTankvolumeVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<BaseCvTankvolumeVO> getById(Integer id) {
        log.info("BaseCvTankvolumeController.getById param : {}", id);
        RestfulResponse<BaseCvTankvolumeVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(baseCvTankvolumeService.getById(id));
        } catch (BaseException e) {
            log.error("BaseCvTankvolumeController.getById ERROR:{}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            log.error("BaseCvTankvolumeController.getById ERROR:{} ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }


    @PostMapping(value = "/del")
    @ApiOperation(value = "删除商品车型油箱容积", notes = "删除商品车型油箱容积",
            produces = MediaType
                    .APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Boolean.class), @ApiResponse(code = -1, message = "系统异常")})
    @ApiImplicitParams({@ApiImplicitParam(paramType = "form", dataType = "Integer", name = "id", value = "油箱容积ID", required = true)})
    public RestfulResponse<Boolean> del(Integer id) {
        log.info("BaseCvTankvolumeController.del params: {}", id);
        RestfulResponse<Boolean> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Boolean blnRtn = baseCvTankvolumeService.del(id);
            result.setData(blnRtn);
        } catch (BaseException e) {
            log.error("BaseCvTankvolumeController.del ERROR:{}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            log.error("BaseCvTankvolumeController.del ERROR:{} ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

}

